package net.xisberto.bustime;

import java.util.ArrayList;

import net.xisberto.bustime.model.Bus;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class BusAdapter extends ArrayAdapter<Bus> {
	private ArrayList<Bus> items;

	public BusAdapter(Context context, int textViewResourceId, ArrayList<Bus> objects) {
		super(context, textViewResourceId, objects);
		this.items = objects;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if (v == null) {
        	LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = inflater.inflate(android.R.layout.simple_list_item_2, null);
		}
        Bus b = items.get(position);
        if (b != null) {
        	TextView bus_name = (TextView) v.findViewById(android.R.id.text1);
            TextView bus_number = (TextView) v.findViewById(android.R.id.text2);
            if (bus_name != null) {
            	bus_name.setText(b.getName());
            }
            if(bus_number != null){
            	bus_number.setText(String.valueOf(b.getNumber()));
            }
        }
		return v;
	}
	

}
